package de.hundezimmer.db;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.Serializable;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;

public class MySQL implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -7645320354548011815L;
	private Connection conn;

	public MySQL(String basepath) throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException {

		Properties prop = new Properties();
		InputStream input = null;

		try {
			input = new FileInputStream(basepath + "/WEB-INF/config/db.config");

			prop.load(input);
			String adress = prop.getProperty("adress", "127.0.0.1");
			String port = prop.getProperty("port", "3306");
			String db = prop.getProperty("db", "hundezimmer");
			String user = prop.getProperty("user", "test");
			String password = prop.getProperty("passwd", "test");

			Class.forName("com.mysql.jdbc.Driver").newInstance();
			setConn(DriverManager.getConnection("jdbc:mysql://" + adress + ":" + port + "/" + db + "", user, password));
		} catch (IOException ex) {
			ex.printStackTrace();
		}
	}

	public Connection getConn() {
		return conn;
	}

	public void setConn(Connection conn) {
		this.conn = conn;
	}

}
